import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent, STPage } from '@delon/abc/table';
import { SFSchema, SFComponent, SFRadioWidgetSchema } from '@delon/form';
import { HttpService, SupDic } from 'lbf';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
// tslint:disable-next-line: use-path-mapping
import { LbWjfwComponent } from '@shared/components/lb_wjfw/lbwjfw.component';
// tslint:disable-next-line: use-path-mapping
import { LbStepsComponent } from '@shared/components/lb-steps/lb-steps.component';
import { ReuseTabService } from '@delon/abc';
import { ActivatedRoute } from '@angular/router';
import { Message } from '@angular/compiler/src/i18n/i18n_ast';
import { LbRepComponent } from '@shared/components/lb-rep/lb-rep.component';

@Component({
  selector: 'app-zyjk-jbyljx',
  templateUrl: './jbyljx.component.html',
})
export class ZyjkJbyljxComponent implements OnInit {
  tabs = ['办件信息', '材料影像'];
  dataset = [];
  PROJID = '1';
  DAD069 = '';
  fordated: any = {};
  isVisible = false;
  dataModal = {};
  fordate1232 = {};
  isOkLoading1 = false;
  isVisible1 = false;


  params = { sname: 'BJXX_QUERY', queryparas: {} };

  slSchema: SFSchema = {
    properties: {
      DAD095: {
        type: 'string',
        title: '',
        enum: [
          { label: '受理', value: '1' },
          { label: '不受理', value: '0' },
        ],
        // tslint:disable-next-line: no-object-literal-type-assertion
        ui: {
          widget: 'radio',
          // asyncData: () => of().pipe(delay(100)),
          change: console.log,
          grid: {
            span: 24,
          },
        } as SFRadioWidgetSchema,
        default: '1',
      },
      DAD098: {
        type: 'string',
        title: '不予受理原因',
        ui: {
          visibleIf: { DAD095: ['0'] },
          spanLabelFixed: 150,
          grid: { span: 24 },
        },
      },
    },
    ui: { grid: { span: 24 } },
    required: ['DAD098'],
  };

  constructor(
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
    private supDic: SupDic,
    private reuseTabService: ReuseTabService,
    private activateroute: ActivatedRoute,
    private modalService: NzModalService,
  ) {
    this.reuseTabService.title = '基本医疗保险转入登记';
  }

  bjxxSchema: SFSchema = {
    properties: {
      AAC002: {
        type: 'string',
        title: '身份证号',
        readOnly: true,
      },

      AAC003: {
        type: 'string',
        title: '姓名',
        readOnly: true,
      },
      AAE173: {
        type: 'string',
        title: 'AAE173',
        default: '1',
        ui: { hidden: true },
      },

      AAC067: {
        type: 'string',
        title: '手机号码',
        readOnly: true,
      },
      AAC010: {
        type: 'string',
        title: '户籍地址',
        readOnly: true,
      },
      AAC009: {
        type: 'string',
        title: '户籍类型',
        enum: this.supDic.getSFDic('AAC009'),
        readOnly: true,
        ui: {
          widget: 'select',
        },
      },
      AAE006: {
        type: 'string',
        title: '联系地址',
        readOnly: true,
      },
      AAB301: {
        type: 'string',
        title: '转入地行政区划代码',
        enum: this.supDic.getSFDic('AAB301'),
        readOnly: true,
      },
      AAC027: {
        type: 'string',
        title: '转出地行政区划代码',
        readOnly: true,
      },
      AKC328: {
        type: 'string',
        title: '转出地机构名称',
      },
      BAE007: {
        type: 'string',
        title: '转出地机构地址',
        readOnly: true,
      },
      AKC330: {
        type: 'string',
        title: '转出地机构邮编',
        readOnly: true,
      },
      AAE005: {
        type: 'string',
        title: '转出地机构电话',
        readOnly: true,
      },
      AAE004: {
        type: 'string',
        title: '转出地机构联系人',
        readOnly: true,
      },
      ACC002: {
        type: 'string',
        title: '医疗保障类型',
        enum: this.supDic.getSFDic('ACC002'),
        readOnly: true,
        ui: {
          widget: 'select',
        },
      },
      AAE040: {
        title: '参保（合）起时间',
        type: 'string',
        format: 'YYYYMM',
        readOnly: true,
        ui: { widget: 'date', displayFormat: 'yyyy-MM', size: 'large' },
      },
      AAE041: {
        title: '参保（合）止时间',
        type: 'string',
        readOnly: true,
        format: 'YYYYMM',
        ui: { widget: 'date', displayFormat: 'yyyy-MM', size: 'large' },
      },
      BAB459: {
        title: '累计缴费月数',
        type: 'number',
        readOnly: true,
        minimum: 0,
        ui: {
          widgetWidth: 210,
        },
      },
      BAE011: {
        title: '省内省外转移标志',
        type: 'string',
        enum: this.supDic.getSFDic('BAE011'),
        readOnly: true,
        ui: {
          widget: 'select',
        },
      },
    },
    ui: {
      spanLabelFixed: 150,
      grid: { span: 8 },
    },
  };

  // 本地获取数据

  sffschema: SFSchema = {
    properties: {
      AAE173: {
        type: 'string',
        title: '转移类型',
        enum: [{ label: '转入', value: '1' }],
        default: '1',
        readOnly: true,
        ui: {
          widget: 'select',
        },
      },
      AAE473: {
        title: '转移账户类别',
        type: 'string',
        enum: this.supDic.getSFDic('AAE473'),
        default: '1',
        ui: {
          widget: 'select',
        },
      },
      AAE140: {
        title: '险种类型',
        type: 'string',
        enum: [{ label: '基本医疗', value: '310' }],
        readOnly: true,
        default: '310',
      },
      AAE013: {
        title: '备注',
        type: 'string',
        ui: {
          grid: { span: 12 },
        },
      },
    },
    ui: {
      spanLabelFixed: 150,
      grid: { span: 8 },
    },
    required: ['AAE473'],
  };

  clsmModal: STColumn[] = [
    { title: '编号', index: 'TID', width: '10%' },
    { title: '对方社保机构名称 ', index: 'SBJG', width: '50%' },
    { title: '社保机构编码 ', index: 'SBJGBM', width: '20%' },
    {
      buttons: [
        {
          type: 'drawer',
          text: '添加',
          click: record => this.handleOk(record),
        },
      ],
    },
  ];

  tabMode = 'bjxx';
  // @ViewChild('st', { static: false }) st: STComponent;
  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('slxx', { static: false }) slxx: SFComponent;
  @ViewChild('wjfw', { static: false }) wjfw: LbWjfwComponent;
  @ViewChild('step', { static: true }) step: LbStepsComponent;
  @ViewChild('sffd', { static: true }) sffd: SFComponent;

  clsmcolumns: STColumn[] = [
    { title: '序号', index: 'RN', width: '10%' },
    { title: '材料名称', index: 'STUFFNAME', width: '50%' },
    { title: '材料数量', index: 'STUFFNUM', width: '25%' },
    { title: '收件类型', index: 'STUFFTYPE', width: '15%' },
  ];
  page: STPage = {
    show: false,
  };

  ngOnInit() {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.YB_QUERY();
      this.YBCL_QUERY();
    }
  }

  // 打开情况下再次传入值
  _onReuseInit(): void {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.YB_QUERY();
      this.YBCL_QUERY();
    }
  }

  // 事项进度
  selectTab(str: string) {
    this.tabMode = str;
    if (str === 'sxjd') {
    }
  }

  // 界面赋值
  YB_QUERY() {
    this.lbservice
      .lbservice('YB_QUERY', { para: { PROJID: this.PROJID } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.fordated = JSON.parse(resdata.message);
          this.kk();

          this.sf.reset();
        }
      });
  }

  // 材料列表
  YBCL_QUERY() {
    this.lbservice
      .lbservice('YBCL_QUERY', {
        para: { PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code === 0) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.dataset = resdata.message.list;
        }
      });
  }

  // 受理保存
  lc_insert(value1: any) {
    // tslint:disable-next-line: all
    if (value1.DAD095 == '0') {
      if (!this.slxx.valid) {
        return this.msgSrv.error('没有填写必填项');
      }

      this.lbservice
        .lbservice('ceshi', {
          para: {
            PROJID: this.PROJID,
            sf: this.sf.value,
            slxx: this.slxx.value,
            sffd: this.sffd.value,
            DAD069: this.DAD069,
          },
        })
        .then(resdata => {
          if (resdata.code < 1) {
            this.msgSrv.error(resdata.errmsg);
          } else {
            this.sf.reset();
            this.msgSrv.info('保存成功');
          }
        });
    } else {
      if (!this.sffd.valid) {
        return this.msgSrv.error('没有填写必填项');
      }

      this.lbservice
        .lbservice('ceshi', {
          para: {
            PROJID: this.PROJID,
            sf: this.sf.value,
            slxx: this.slxx.value,
            sffd: this.sffd.value,
            DAD069: this.DAD069,
          },
        })
        .then(resdata => {
          if (resdata.code < 1) {
            this.msgSrv.error(resdata.errmsg);
          } else {
            this.sf.reset();
            this.msgSrv.info('保存成功');
            this.isVisible1 = true;

          }
        });
    }
  }
  // 处理 转出 地
  kk() {
    this.lbservice
      .lbservice('zctcq_a', {
        para: { sf: this.fordated },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.fordated.AAC027 = resdata.message.list[0].AAA103;
          this.sf.reset();
        }
      });
  }

  onEnter(value1: any) {
    this.lbservice
      .lbservice('L_YB_aa33', {
        para: { AKC328: value1.AKC328 },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.dataModal = resdata.message.list;
        }
      });

    this.isVisible = true;
  }
  handleCancel() {
    this.isVisible = false;
  }
  handleOk(record: any) {
    this.fordated.AKC328 = record.SBJG;
    this.sf.reset();
    this.isVisible = false;
  }
  handleCancel1(): void {
    this.isVisible1 = false;
  }

 //是否打印页面
 handleOk1(): void {
  this.isOkLoading1 = true;
  this.print();
  setTimeout(() => {
    this.isVisible1 = false;
    this.isOkLoading1 = false;
  }, 3000);
}
  // 转入联系函打印
  print() {
    this.lbservice
      .lbservice('p_dayin', {
        para: { sf: this.sf.value },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.fordate1232 = resdata.DAC133;
          console.log(this.fordate1232.toString());
          const modal = this.modalService.create({
            nzTitle: '打印',
            nzContent: LbRepComponent,
            nzComponentParams: {
              repid: '53',
              inpara: { DAD069: this.DAD069 },
            },
            nzWidth: 1000,
          });
        }
      });
  }

  // tslint:disable-next-line: member-ordering
  pl = {
    pname: '省端转入数据',
    active: true,
    pname1: '本地获取数据',
    active1: false,
    icon1: 'caret-right',
  };
}
